
package com.eva.framework;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.eva.framework.utils.LoggerFactory;


/**
 * A servlet listener to listen all events of application init or destroy
 * and the creation or destroy of user session etc.
 *
 * @version 1.0
 */
public class WebListener extends HttpServlet implements ServletContextListener ,HttpSessionListener
{
	/**
	 * The web module is ready to process requests.
	 */
	public void contextInitialized(ServletContextEvent servletContextEvt)
	{
		LoggerFactory.getLog().info("基于EVA.EPC平台的J2EE模块已经被始化了!");
		ServletContext context=servletContextEvt.getServletContext();
	}

	/**
	 * The servlet context is about to be shut down.
	 */
	public void contextDestroyed(ServletContextEvent servletContextEvt)
	{
		LoggerFactory.getLog().info("基于EVA.EPC平台的J2EE模块已经被注销了!");
	}

	/**
	 * A session was created.
	 */
	public void sessionCreated(HttpSessionEvent httpSessionEvt)
	{
		HttpSession session = httpSessionEvt.getSession();
		ServletContext context=session.getServletContext();
		LoggerFactory.getLog().info("用户会话: "+session.getId()+"已经建立!");
	}

	/**
	 * A session was invalidated.
	 */
	public void sessionDestroyed(HttpSessionEvent httpSessionEvt)
	{
		HttpSession session=httpSessionEvt.getSession();
		LoggerFactory.getLog().info("用户会话:"+session.getId()+"已经注销!");
	}
}
